package com.zut.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.base.entity.Directory;
import com.zut.base.entity.Project;
import com.zut.base.entity.Projectanduser;
import com.zut.base.mapper.DirectoryMapper;
import com.zut.base.mapper.ModuleanduserMapper;
import com.zut.base.mapper.ProjectanduserMapper;
import com.zut.base.service.IDirectoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zut.base.service.IProjectanduserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 目录表 服务实现类
 * </p>
 *
 * @author yyl
 * @since 2021-03-31
 */
@Service
public class DirectoryServiceImpl extends ServiceImpl<DirectoryMapper, Directory> implements IDirectoryService {

    @Autowired
    private ProjectanduserMapper projectanduserMapper;

    @Override
    public List<Directory> getDirListByUserId(String id) {
        List<Map<String,Object>> list = projectanduserMapper.getProjectListByUserId(id);
        Set<String> set = new HashSet<>();
        for(Map map : list){
            set.add(String.valueOf(map.get("id")));
            set.add(String.valueOf(map.get("parentId")));
        }
        if(set.size() <= 0) return null;
        List<Directory> dir = projectanduserMapper.getDirListById(new ArrayList<String>(set));
        return dir;
    }

    @Override
    public List<Directory> getDirListSec(String id, String dirId) {
        List<Map<String,Object>> list = projectanduserMapper.getProjectListByUserId(id);
        Set<String> set = new HashSet<>();
        for(Map map : list){
            String parentId = String.valueOf(map.get("parentId"));
            if(parentId.equals(dirId))
            set.add(String.valueOf(map.get("id")));
        }
        if(set.size() <= 0) return null;
        List<Directory> dir = projectanduserMapper.getDirListById(new ArrayList<String>(set));
        return dir;
    }
}
